//@author A0078695H
#include "CmdHelp.h"
#include "logger.hpp"
using namespace std;

vector<vector<string>> CmdHelp::COMMAND_HELP_STR_ARR(15, vector<string>());

int CmdHelp::loadHelpInfo(string filename) {
	ifstream read;
	read.open(filename);
	if (read.is_open()) {
		string line;
		getline(read, line);
		if (line != "HelpInfo") {
			log(LOG_INFO) << "Can't load Help Info. Proceed.";
			return 1;
		}
		assert(line == "HelpInfo");
		int i = 0;
		while (getline(read, line)) {
			if (line == "HEREDOC;") {
				i++; continue;
			}
			else {
				CmdHelp::COMMAND_HELP_STR_ARR[i].push_back(line);
			}
		}
		return 0;
	}
	else {
		log(LOG_INFO) << "Can't load Help Info. Proceed.";
		return 1;
	}
}

string CmdHelp::toHelpInfoString(cmdTypes helptype = cmdTypes::HELP) {
	string res = "";
	//BY
	//cout << "In tohelpinfo string" << endl;
	//for (int i=0; i<CmdHelp::COMMAND_HELP_STR_ARR.size(); i++) { // every cmd
		for (int j=0; j<CmdHelp::COMMAND_HELP_STR_ARR[helptype].size(); j++) { // every line
			res += CmdHelp::COMMAND_HELP_STR_ARR[helptype][j];
			res += "\n";
		}
	//}
	return res;
}
string CmdHelp::toHelpInfoHtml(cmdTypes helptype = cmdTypes::HELP) {
	string res = "";
	for (int j=0; j<CmdHelp::COMMAND_HELP_STR_ARR[helptype].size(); j++) { // every line
		if (j == 0) {
			res += "<h2>" + COMMAND_HELP_STR_ARR[helptype][0] + "</h2>";
		}
		else {
			res += CmdHelp::COMMAND_HELP_STR_ARR[helptype][j];
		}
		res += "<br>";
	}
	return res;
}
CmdHelp::~CmdHelp(void)
{
}

cmdTypes CmdHelp::getHelpType() {
	return this->helpType;
}

CmdHelp::CmdHelp(cmdTypes cmdType, vector<string> params, string origStr, cmdTypes helpT) : 
	Cmd(cmdType, params, origStr) {
	this->helpType = helpT;
}